const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardList: [],
    empty: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      role: wx.getStorageSync('role')
    })
    this.getSellCardList();
  },


  //跳转到分享界面
  navShare(e) {
    const {
      item
    } = e.currentTarget.dataset;

    wx.navigateTo({
      url: '../share/share',
      success: res => {
        res.eventChannel.emit('acceptDataFromOpenerPage', item)
      }
    })
  },

  navSetting(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../setting/setting?id=' + id,
    })
  },


  getSellCardList() {
    let url = this.data.role == 2 ? 'Salesman/Recharge/getCardList' : "Partner/Recharge/getCardList";
    app.ajax({
      url,
      success: res => {
        if (res.data.code == 1000) {
          const data = res.data.data;
          const filter = data.filter(item => {
            return item.card_data.length > 0;
          });
          if (filter.length == 0) {
            this.setData({
              empty: true
            })
          } else {
            this.setData({
              cardList: filter,
              empty: false
            })
          }
        } else {
          app.showToast(res.data.message);
        }
      }
    })
  },

  previewImage(e) {
    const current = e.currentTarget.dataset.current;
    wx.previewImage({
      current,
      urls: [current],
    })
  }



})